#include "HermiteInterpolation.h"
#include <iostream>
#include <vector>
using namespace std;
int main() {
    cout << "Problem D is running." << endl;
    // 时间点
    vector<double> t = {0, 3, 5, 8, 13};
    // 位移（位置）
    vector<double> s = {0, 225, 383, 623, 993};
    // 速度（导数）
    vector<double> v = {75, 77, 80, 74, 72};

    // 预测的位置和速度
    double t_predict = 10.0;
    PositionAndVelocity pv = hermiteInterpolation(t, s, v, t_predict);
    cout << "Predicted position at t=" << t_predict << " seconds: " << pv.position << " feet" << endl;
    cout << "Predicted velocity at t=" << t_predict << " seconds: " << pv.velocity << " feet/second" << endl;

    // 检查是否超过速度限制
    double speed_limit = 81.0; // 55 mph in feet per second
    bool exceeds_speed_limit = false;
    for (double ti = 0; ti <= 13; ti += 0.01) {
        PositionAndVelocity pv = hermiteInterpolation(t, v, s, ti); // 注意：这里需要速度的导数，即加速度
        if (pv.velocity > speed_limit) {
            exceeds_speed_limit = true;
            cout << "The car exceeds the speed limit of 81 feet/second at first time at t = " << ti << endl;
            break;
        }
    }

    if (exceeds_speed_limit) {
        cout << "The car exceeds the speed limit of 81 feet/second." << endl;
    } else {
        cout << "The car does not exceed the speed limit." << endl;
    }

    return 0;
}